import Vue from 'vue';
import Vuex from 'vuex';
import { ISettingState } from './modules/setting'
import { IAppState } from './modules/app'
import { IUserState } from './modules/user'
import { IPermissionState } from './modules/permission'

import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex);

export interface IRootState {
  setting: ISettingState,
  app: IAppState,
  user: IUserState,
  permission: IPermissionState
}

const store = new Vuex.Store<IRootState & any>({
  plugins: [
    createPersistedState({
      paths: [
        'app',
        'permission',
        'user'
      ],
      storage: window.sessionStorage
    }),
    createPersistedState({
      paths: [
        'setting'
      ],
      storage: window.localStorage
    })
  ]
});

export default store

